<?php
/**
 * Created by PhpStorm.
 * User: w-pc
 * Date: 2017/03/07
 * Time: 17:11
 */
namespace Common\Model;
use Think\Model;

class MessageModel extends Model{

    private $_db = '';

    public function __construct() {
        $this->_db = M('message');
    }

    /**根据留言状态来返回列表
     * @param $tip 留言的状态
     * @return mixed
     */
    public function get_MessageList($m_state){
        if($m_state==1){
            $where['m_state'] = 1;
        }else if($m_state==2){
            $where['m_state'] = 2;
        }else if($m_state==3){
            $where['m_state'] = 3;
        }else{
            $where['m_state'] = 1;
        }
        $message_list = $this->_db->where($where)->select();
        return $message_list;
    }

    /**返回单条留言
     * @param $m_id 留言id
     * @return mixed
     */
    public function get_Message($m_id){
        $where['m_id'] = $m_id;
        $message = $this->_db->where($where)->find();
        return $message;
    }

    /**修改留言
     * @param $m_id 留言id
     * @param $data
     */
    public function set_Message($m_id,$data){
        $where['m_id'] = $m_id;
        $this->_db->where($where)->save($data);
    }
    public function add_Message($data){
        $this->_db->where()->add($data);
    }

    /**留言的置顶，显示，删除等操作
     * @param $m_id
     */
    public function set_Stick($m_id){
        $message = $this->get_Message($m_id);
        if($message['m_state']==1){
            $message['m_state'] = 2;
        }else if($message['m_state']==2){
            $message['m_state'] = 1;
        }else if($message['m_state']==3){
            $message['m_state'] = 1;
        }
        $this->set_Message($m_id,$message);
    }

    /**删除留言
     * @param $m_id
     */
    public function set_Delete($m_id){
        $message = $this->get_Message($m_id);
        $message['m_state'] = 3;
        $this->set_Message($m_id,$message);
    }
}